package com.snail.billing.fragment;

import android.view.View;
import android.widget.TextView;

import com.android.os.Page;
import com.android.util.ResUtil;
import com.snail.billing.DataCache;
import com.snail.billing.PaymentConst;
import com.snail.billing.Resource;
import com.snail.billing.data.PaymentLogic;

public class PaymentOkFragment extends Page implements View.OnClickListener {

	private TextView textTitle;
	private View buttonBack;

	private TextView textMessage;
	private View buttonOk;

	private int state;

	@Override
	public int createLayoutId() {
		return ResUtil.getLayoutId(Resource.layout.snailbilling_pay_payment_ok_activity);
	}

	@Override
	public void onCreate() {
		super.onCreate();
		state = getPageArgs().getInt("state");
		textTitle = (TextView) findViewById(ResUtil.getViewId(Resource.id.snailbilling_title_text));
		DataCache cache = DataCache.getInstance();
		if (state == PaymentLogic.STATE_IMPREST
		//
				|| state == PaymentLogic.STATE_IMPREST2) {
			textTitle.setText("充值结果");
		} else if (state == PaymentLogic.STATE_PAYMENT) {
			textTitle.setText("支付结果");
		}
		buttonBack = findViewById(ResUtil.getViewId(Resource.id.snailbilling_title_button_back));
		buttonBack.setOnClickListener(this);
		//
		textMessage = (TextView) findViewById(ResUtil.getViewId(Resource.id.snailbilling_pay_payment_ok_text_message));
		buttonOk = findViewById(ResUtil.getViewId(Resource.id.snailbilling_pay_payment_ok_button_ok));
		buttonOk.setOnClickListener(this);
		if (state == PaymentLogic.STATE_IMPREST
		//
				|| state == PaymentLogic.STATE_IMPREST2) {
			if (cache.paymentParams.platformId == PaymentConst.TYPE_SNAIL_CARD) {
				textMessage.setText("已经成功充值\n卡号: " + cache.paymentParams.cardNo);
			} else {
				int money = cache.paymentParams.card.getMoney() * cache.paymentParams.amount;
				textMessage.setText("已经成功充值" + money + cache.paymentParams.card.getCurrencyName());
			}
		} else if (state == PaymentLogic.STATE_PAYMENT) {
			textMessage.setText("已经成功支付\n商品: " + cache.importParams.produceName);
		}
	}

	@Override
	public void onClick(View v) {
		if (v.equals(buttonBack)) {
			getPageManager().finish();
		} else if (v.equals(buttonOk)) {
			getPageManager().finish();
		}
	}
}
